package com.cqw.order.enums;

import com.cqw.enums.BaseEnum;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-07-12 22:38
 * @Description:
 */
public enum SpuStateEnum implements BaseEnum {

    DELETE(0, "已删除"),
    NO_LINE(1, "未上架"),
    ON_LINE(2, "已上架");

    private static final Map<Integer, SpuStateEnum> typeMap =
            Arrays.stream(SpuStateEnum.values()).collect(Collectors.toMap(SpuStateEnum::code, t -> t));

    private static final Map<String, SpuStateEnum> typeByNameMap =
            Arrays.stream(SpuStateEnum.values()).collect(Collectors.toMap(spuStateEnum -> spuStateEnum.value, Function.identity()));


    private final Integer code;

    private final String value;

    SpuStateEnum(int code, String value) {
        this.code = code;
        this.value = value;
    }

    public static SpuStateEnum parse(int code) {
        return typeMap.get(code);
    }

    public static SpuStateEnum parse(String value) {
        return typeByNameMap.get(value);
    }

    @Override
    public Integer code() {
        return this.code;
    }

    @Override
    public String value() {
        return this.value;
    }
}
